// page/index//pages/fabu/fabu.js
var area = require('../../../../utils/area.js');

Page({

  /**
   * 页面的初始数据
   */
  data: {
    daoyou: [{ name: '导游', isSelected: false, }, { name: '领队', isSelected: false, }, { name: '讲解员', isSelected: false, }],
    lao_tong: [{ name: '老人同行', isSelected: false, }, { name: '儿童同行', isSelected: false, }],
    li:['1年以内','1~3年','3~5年','5~10年','10年以上'],
    sex:['男','女'],
    jineng: [{ name: '会潜水', isSelected: false, }, { name: '会摄影', isSelected: false, }, { name: '会急救', isSelected: false, }, { name: '会开车', isSelected: false, }],
    yuyan: [{ name: '普通话', isSelected: false, }, { name: '英语', isSelected: false, }, { name: '日语', isSelected: false, }, { name: '法语', isSelected: false, }, { name: '葡萄牙语', isSelected: false, }, { name: '西班牙语', isSelected: false, }, { name: '周天', isSelected: false, },{ name: '德语', isSelected: false, }],
    show: false,
    date: '',
    city:'',
    show_calendar: false,
    areaList:area.default,
    show_area:false,
    show_del:false,
    //editor
    html: '',
    option: { 
      placeholder: '请详细输入游玩路线，以便快速找到导游', //占位符默认为 '请输入文字...'
      imgUp: false, //插入图片功能默认开启
      width: '100%', //默认宽100%
      height: '600rpx', //默认高200px
      flag:false
    }
    
  },
  //日历开关
  onDisplay_calendar() {
    this.setData({ show_calendar: true });
  },
  onClose_calendar() {
    this.setData({ show_calendar: false });
  },
  formatDate(date) {
    date = new Date(date);
    return `${date.getFullYear() + 1}/${date.getMonth() + 1}/${date.getDate()}`;
    return `${date.getMonth() + 1}/${date.getDate()}`;
  },
  onConfirm_calendar(event) {
    const [start, end] = event.detail;
    this.setData({
      show_calendar: false,
      date: `${this.formatDate(start)} - ${this.formatDate(end)}`,
    });
  },
  //选择地区
  onClickShow() {
    this.setData({ show_area: true });
  },
  area_confirm(e){
    this.setData({ 
      show_area: false ,
      city: e.detail.values[1].name
    });
  },
  onClickHide(){
    this.setData({ show_area: false });
  },
   //编辑删除
   onClickShow_del() {
    this.setData({ show_del: true });
  },
  del_confirm(e){
    this.setData({ 
      show_del: false 
    });
  },
  onClickHide_del(){
    this.setData({ show_del: false });
  },
  //遮罩 的开关
  showPopup() {
    this.setData({ show: true });
  },

  onClose() {
    this.setData({ show: false });
  },

  prop_succ(){
    if(!this.data.jineng_text){
      wx.showToast({
        title: '请输入技能名称',
        icon:'none'
      })
      return false;
    }
    this.data.jineng.push({'name': this.data.jineng_text,'isSelected':false});
    this.setData({
      jineng:this.data.jineng,
      show: false,
      jineng_text:''
    })
  },
  //点击事件
  bindTab: function (e) {
    var that = this;
    that.setData({
      currentTab: e.currentTarget.dataset.index,
    })
  },
  bind_sex: function (e) {
    var that = this;
    that.setData({
      current_sex: e.currentTarget.dataset.index,
    })
  },
  bind_age: function (e) {
    var that = this;
    that.setData({
      current_age: e.currentTarget.dataset.index,
    })
  },
  bind_feiyong: function (e) {
    var that = this;
    that.setData({
      current_feiyong: e.currentTarget.dataset.index,
    })
  },
  daoyou:function(e){
    var index = e.currentTarget.dataset.index;
    var item = this.data.daoyou[index];
    item.isSelected = !item.isSelected;
    this.setData({
      daoyou: this.data.daoyou,
    });
    //后台接口需要 整合数组
    var arr = [];
    for (var i = 0; i < this.data.daoyou.length; i++) {
      if (this.data.daoyou[i].isSelected == true) {
        arr.push(this.data.daoyou[i].name);
      }
    }
    this.setData({
      arr_daoyou: arr
    })
  },
  lao_tong:function(e){
    var index = e.currentTarget.dataset.index;
    var item = this.data.lao_tong[index];
    item.isSelected = !item.isSelected;
    this.setData({
      lao_tong: this.data.lao_tong,
    });
    //后台接口需要 整合数组
    var arr = [];
    for (var i = 0; i < this.data.lao_tong.length; i++) {
      if (this.data.lao_tong[i].isSelected == true) {
        arr.push(this.data.lao_tong[i].name);
      }
    }
    this.setData({
      arr_lao_tong: arr
    })
  },
  li:function(e){
    var index = e.currentTarget.dataset.index;
    var item = this.data.yuyan[index];
    item.isSelected = !item.isSelected;
    this.setData({
      yuyan: this.data.yuyan,
    });
    //后台接口需要 整合数组
    var arr = [];
    for (var i = 0; i < this.data.yuyan.length; i++) {
      if (this.data.yuyan[i].isSelected == true) {
        arr.push(this.data.yuyan[i].name);
        console.log(arr)
      }
    }
    this.setData({
      arr: arr
    })
  },
  jineng:function(e){
    var index = e.currentTarget.dataset.index;
    var item = this.data.jineng[index];
    item.isSelected = !item.isSelected;
    this.setData({
      jineng: this.data.jineng,
    });
    //后台接口需要 整合数组
    var arr = [];
    for (var i = 0; i < this.data.jineng.length; i++) {
      if (this.data.jineng[i].isSelected == true) {
        arr.push(this.data.jineng[i].name);
      }
    }
    this.setData({
      arr_jineng: arr
    })
  },
  focus(){
   this.data.option.flag = false;
   this.setData({
    option:this.data.option
   })
  },
  dd(){
    this.data.option.flag = true;
    this.setData({
      option:this.data.option
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    //初始化富文本的内容
    var that = this;
    // setTimeout(function(){
    //   that.selectComponent('#hf_editor').setContents('<p>121212121212</p>')
    // },1000)
  },
  //editor
  getHtml(e) {//从组件获取值
    this.html = e.detail.content.html
  },
  submit() {
    console.log('提交的富文本', this.html)
  },
  insertImage(){ //图片上传插入示例
    var that = this;
    wx.chooseImage({
      count: 1,
      success: res => {
        console.log(res);
        that.selectComponent('#hf_editor').insertSrc(
          res.tempFilePaths[0]
        )
        // wx.uploadFile({ //调用图片上传接口
        //   url: 'http://192.168.1.61:3000/upload', 
        //   filePath: res.tempFilePaths[0],
        //   name: 'imgFile',
        //   success: res => {
        //     let imgUrl = JSON.parse(res.data).url
        //     this.selectComponent('#hf_editor').insertSrc('http://192.168.1.61:3000' + imgUrl);//调用组件insertSrc方法
        //   }
        // })
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
   
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})